package com.wust.tieshi;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import com.wust.R;
import com.wust.loveangel.loveAngelActivity;
import com.wust.loveangel.loveAngelActivity2;
import com.wust.menu.SecondGroupTab;
import com.wust.menu.ThirdGroupTab;
import com.wust.task.Task;
import com.wust.task.TaskDao;


import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class noticeActivity extends ListActivity {
	private List<Task>tasklist;
	private TaskDao taskDao;
	private ListView listv=null;
	private ImageButton imgbtn=null;
	private ArrayList<HashMap<String, Object>> listItems;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.notice_list);
		taskDao=new TaskDao(this);
		imgbtn=(ImageButton)findViewById(R.id.img_add_notice);
		
		imgbtn.setOnClickListener(new ImgListener());
	}
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		listv=getListView();
		listv.setAdapter(buildAdapter());
		super.onResume();
	}
	private  SimpleAdapter buildAdapter(){
		tasklist=taskDao.queryTasks();
		listItems = new ArrayList<HashMap<String, Object>>();    
		for (Iterator iterator = tasklist.iterator(); iterator.hasNext();) {
			Task task = (Task) iterator.next();
        HashMap<String, Object> map1 = new HashMap<String, Object>();           
        map1.put("date", task.getDate1());//图片   
        map1.put("content", task.getCreated());
        listItems.add(map1); 
		}
           
        //生成适配器的Item和动态数组对应的元素       
        SimpleAdapter listItemAdapter = new SimpleAdapter(this,listItems,//数据源        
            R.layout.notice_list_item,//ListItem的XML布局实现       
            //动态数组与ImageItem对应的子项               
            new String[] {"date", "content"},        
            //ImageItem的XML文件里面的一个ImageView,两个TextView ID       
            new int[] {R.id.notice_date, R.id.notice_content}       
        ); 
        return listItemAdapter;
	}
	private void buildList(){
		listv.setAdapter(buildAdapter());
	}
	@Override  
    public void onBackPressed() {   
        //把后退事件交给子Activity处理  
		Intent intent = new Intent(noticeActivity.this, ViewTestActivity.class);  
        // 把Activity转换成一个Window，然后转换成View  
        Window w =SecondGroupTab.group.getLocalActivityManager()  
                .startActivity("noticeActivity",intent);  
        View view = w.getDecorView();  
        //设置要跳转的Activity显示为本ActivityGroup的内容  
        SecondGroupTab.group.setContentView(view);  
    } 
	class ImgListener implements OnClickListener{
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Intent intent=new Intent();
			intent.setClass(noticeActivity.this, AlarmAddActivity.class);
			startActivity(intent);
		}
	}
}

